package Gui;

import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import Logic.LoginInfo;

import client.LibaryMain;
/**
 * this class implements gui of extend lending  
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class ExtendLending extends JPanel {
	private JTextField textField;
	/**
	 * this method initilaizing extends lending window 
	 */
	public ExtendLending() {
		setBackground(new Color(153, 204, 255));
		
		JLabel lblExtendLending = new JLabel("EXTEND LENDING");
		lblExtendLending.setFont(new Font("Tahoma", Font.PLAIN, 20));
		
		JLabel lblBookId = new JLabel("Book ID");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("Extend ");
		
		btnNewButton.addActionListener(new java.awt.event.ActionListener() {     // Login action listener 
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	extendActionPerformed(evt);
            
            }

		private void extendActionPerformed(ActionEvent evt) {
			String name=LoginInfo.UserName;//complete whene login fix
			//String name=subscriberidtext.getText();
			ArrayList<String> Arr=new ArrayList<String>();
            Arr.add("ExtendLending");
            String bookid=textField.getText();
            Arr.add(bookid);
            Arr.add(name);
            System.out.println(name);
            LibaryMain.chat.handleMessageFromGui(Arr);
    		
			
		}
        });
		
		JButton btnBack = new JButton("back");
		btnBack.addActionListener(new java.awt.event.ActionListener() {     
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnback(ev);
            					
			}

			private void btnback(ActionEvent ev) {
				MainScreen.cardLayot.show(MainScreen.card, "SubscriberWindow");
				
			}
        });
		
		
		JButton btnLogout = new JButton("LogOut");
		btnLogout.addActionListener(new java.awt.event.ActionListener() {      
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnLogOut(ev);
            					
			}

			private void btnLogOut(ActionEvent ev) {
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("Subscriber");
				Arr.add(LoginInfo.UserName);
				LibaryMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
			}
        });
		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(139)
					.addComponent(lblExtendLending))
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(btnBack)
					.addPreferredGap(ComponentPlacement.RELATED, 308, Short.MAX_VALUE)
					.addComponent(btnLogout)
					.addContainerGap())
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(53)
					.addComponent(lblBookId)
					.addGap(41)
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(39)
					.addComponent(btnNewButton)
					.addGap(127))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addComponent(lblExtendLending)
					.addGap(39)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblBookId)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton))
					.addPreferredGap(ComponentPlacement.RELATED, 156, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnBack)
						.addComponent(btnLogout))
					.addContainerGap())
		);
		setLayout(groupLayout);
	}
}
